package com.morningstar.system.listener;

import com.morningstar.system.handler.MessageHandler;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import static com.morningstar.common.constants.QueueConstant.MESSAGE_QUEUE;

@Slf4j
@Component
@RabbitListener(queues = MESSAGE_QUEUE, containerFactory = "containerFactory")
public class MessageListener {


    @Resource
    private MessageHandler messageHandler;

    @RabbitHandler
    public void listener(String message) {
        try {
            messageHandler.handler(message);
        } catch (Exception e) {
            log.error("message listener {}", ExceptionUtils.getStackTrace(e));
        }
    }
}
